// 登陆
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { userInfoType } from './type'
import { mobilePasswordLogin } from "@renderer/api/login"
export const useLoginStore = defineStore('login', () => {
    const userInfo = ref<userInfoType['userInfo']>()
    const token = ref<string>('')
    const moPaLogin = async (mobile: string, password: string) => {
        const res = await mobilePasswordLogin(mobile, password)
        if(res.code == 0){
            userInfo.value = res.userInfo
            token.value = res.token
            return res
        }
    }
    return {
        userInfo,
        moPaLogin,
        token,
    }
},
    {
        persist: {
            key: 'token',
            storage: localStorage,
            paths: ['token']
        }
    }
)